package com.ejlchina.tool.fragment

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager
import com.adolf.androiddemo.databinding.DialogIndexFixFailBinding
import com.ejlchina.tool.adapter.IndexFixFailDialogAdapter
import com.ejlchina.tool.base.BaseDialogFragment
import com.ejlchina.tool.network.IndexFixUpdateFailBean
import com.ejlchina.tool.view.HorizontalItemDecoration

class IndexFixFailDialogFragment: BaseDialogFragment() {
    private lateinit var binding: DialogIndexFixFailBinding

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        binding = DialogIndexFixFailBinding.inflate(inflater,container,false)
        return binding.root
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        initViews()
        initData()

    }

    private fun initViews(){
        initListeners()
    }

    private fun initListeners(){
        binding.ivClose.setOnClickListener {
            dismiss()
        }

        binding.btnConfirm.setOnClickListener {
            dismiss()
        }
    }

    private fun initData(){
        arguments?.getParcelableArrayList<IndexFixUpdateFailBean>(BUNDLE_INDEX_FIX_FAIL_LIST)?.let { list ->
            binding.recyclerView.apply {
                adapter = IndexFixFailDialogAdapter(list)
                layoutManager = LinearLayoutManager(requireContext())
                if (itemDecorationCount == 0){
                    addItemDecoration(HorizontalItemDecoration())
                }
            }
        }
    }
}